<template>
  <teleport to="#back">
    <div class="loading-container d-flex align-items-center justify-content-center w-100 h-100" :style="{backgroundColor: background || ''}">
      <div class="loading-content">
        <div class="spinner-border text-primary" role="status">
          <span class="visually-hidden">{{text || 'Loading'}}</span>
        </div>
      </div>
      <p v-if="text" class="small text-primary my-0">{{text}}</p>
    </div>
  </teleport>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useCreateNode } from '../hooks/usecreateNode'

export default defineComponent({
  name: 'Loading',
  props: {
    text: {
      type: String
    },
    background: {
      type: String
    }
  },
  setup () {
    useCreateNode('back')
    // const newDiv = document.createElement('div')
    // newDiv.id = 'back'
    // document.body.appendChild(newDiv)
    // onUnmounted(() => {
    //   document.body.removeChild(newDiv)
    // })
  }
})
</script>

<style scoped>
.loading-container {
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(255, 255, 255, .5);
  z-index: 100;
}
.loading-content {
  text-align: center;
}
</style>
